using System;
using System.Collections;

using Evaluant.Uss.ObjectContext.Descriptors;

namespace NUnit.DynamicProxy
{

	public enum  TitleEnum { Miss, Madam, Sir }
	public enum KindEnum { Nice, Bad }

	[Serializable]
	public class Person
	{
		public Person()
		{
			this.birth = DateTime.Now;
		}

		protected string _Name;

		[PersistentProperty ("_Name")]
		public string Name
		{
			get { return _Name; }
			set { _Name = value; }
		}

		protected int m_Age;

		[PersistentProperty ("m_Age")]
		public int Age
		{
			get { return m_Age; }
			set { m_Age = value; }
		}

		protected DateTime birth;

		[PersistentProperty ("birth")]
		public DateTime Birth
		{
			get { return birth; }
			set { birth = value; }
		}

		protected IList partners = new ArrayList();

		[PersistentProperty ("partners", typeof(Person))]
		public IList Partners // Lists must contain a setter in case the Property is used to get/set the data
		{
			get { return partners; }
			set { partners = value; }
		}

        public bool BaseAddressGetterCalled = false; // Used to test if the Dynamic Proxy calls the base getter

		protected Address m_address;

		[PersistentProperty ("m_address", true)]
		public virtual Address Address
		{
			get 
			{
				BaseAddressGetterCalled = true;
				return m_address; 
			}
			set { m_address = value; }
		}

		protected string _PersonId;

		[PersistentId("_PersonId")]
		public string PersonId
		{
			get { return _PersonId; }
			set { _PersonId = value; }
		}
		
		protected TitleEnum _Title;

		[PersistentProperty("_Title")]
		public TitleEnum Title
		{
			get { return _Title;  }
			set { _Title = value; }
		}

		protected KindEnum _Kind;

		[PersistentProperty("_Kind", typeof(int))]
		public KindEnum Kind
		{
			get { return _Kind; }
			set { _Kind = value; }
		}

		protected string _Marks;

		public int[] Marks
		{
			get
			{
				string[] coll = _Marks.Split(new char[] { ',' });
				int[] ret = new int[coll.Length];
				for (int i = 0; i < coll.Length; i++)
					ret[i] = Convert.ToInt32(coll[i]);
				return ret;
			}
			set
			{
				string[] coll = new string[value.Length];
				for (int i = 0; i < value.Length; i++)
					coll[i] = Convert.ToString(value[i]);
				_Marks = string.Join(", ", coll);
			}
		}
	}
}
